import { createSlice } from "@reduxjs/toolkit";

const userSlice = createSlice({
    name: "user",
    initialState: {
        storeList: localStorage.getItem('storeList') ? JSON.parse(localStorage.getItem('storeList') as string) : {},
        userId: localStorage.getItem('userId') || ''
    },
    reducers: {
        setStoreList(state, action) {
            state.storeList = action.payload;
            localStorage.setItem('storeList', JSON.stringify(action.payload))
        },
        setUserId(state, action) {
            state.userId = action.payload;
            localStorage.setItem('userId', action.payload)
        }
    }
})

export const { setStoreList, setUserId } = userSlice.actions
export default userSlice